package bit.book.mapper;

import bit.book.entity.BookInfo;
import bit.book.entity.PageRequest;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;

@Mapper
public interface BookMapper {

    @Insert("insert into book_info (book_name,author,count,price,publish,status) values (#{bookName},#{author" +
            "},#{count},#{price},#{publish},#{status})")
    void addBook(BookInfo book);

    //SQL 查询中不应使用 (#{page}-1)*#{size} 这种运算。此方法废弃
//    @Select("select * from book_info where status!=0 limit (#{page}-1)*#{size},#{size}")
//    List<BookInfo> getBookListByPage(@Param("page") Integer page, @Param("size") Integer size);


    @Select("select count(1) from book_info where `status`!=0")
    Integer countBookByPage();

    @Select("select * from book_info where status!=0 limit #{offset},#{size}")
    List<BookInfo> getBookListByPage(PageRequest pageRequest);

    @Select("select * from book_info where status!=0 and id=#{bookId}")
    BookInfo queryBookById(Integer bookId);



    void updateBook(BookInfo book);

    Integer batchDelete(List<Integer> ids);
}
